#ifndef L2_D202503_H
#define L2_D202503_H

#include <algorithm>
#include <iostream>
using namespace std;

// Q1 投票
void Q1() {
  int yes = 0, no = 0, value = 0;
  while (true) {
    cin >> value;
    if (value == 1) {
      yes++;
    } else if (value == 0) {
      no++;
    } else if (value == -1) {
      break;
    } else {
      cout << "非法输入！请输入 1 同意 0 不同意 -1 结束。" << endl;
    }
  }
  string result = yes > no ? "Yes" : (yes == no ? "Tie" : "No");
  cout << result << endl;
  cout << yes << ":" << no << endl;
}

// Q2 千年一遇对称日
bool isLeapYear(int year) {
  return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
// 获取某月天数
int getDaysInMonth(int year, int month) {
  int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  if (month == 2 && isLeapYear(year)) {
    return 29;
  }
  return days[month - 1];
}
// 获取日期
string getDate(int year, int month, int day) {
  string y, m, d;
  y = to_string(year);
  while (y.size() < 4) {
    y = "0" + y;
  }
  m = to_string(month);
  while (m.size() < 2) {
    m = "0" + m;
  }
  if (m.size() < 2) {
    m = "0" + m;
  }
  d = to_string(day);
  if (d.size() < 2) {
    d = "0" + d;
  }
  return y + m + d;
}
// 判断某日是否为对称日
bool isSymmetry(string date) {
  string temp = date;
  reverse(date.begin(), date.end());
  return date == temp;
}
void Q2() {
  string name, time;
  // cin >> name >> time;
  name = "Katherine Johnson";
  time = "19180826 - 20200224";
  int start_year = stoi(time.substr(0, 4)), end_year = stoi(time.substr(11, 4));
  // time.
  cout << name << endl;
  int y = start_year;
  while (y <= end_year) {
    for (int m = 1; m <= 12; m++) {
      int day = getDaysInMonth(y, m);
      for (int d = 1; d <= day; d++) {
        string date = getDate(y, m, d);
        if (isSymmetry(date)) {
          cout << date << endl;
        }
      }
    }
    y++;
  }
}

// Q3 六翻了
void Q3() {
  string words, result;
  // getline 读取输入，保证能包含空格字符
  getline(cin, words);

  int i = 0, count = 0;
  while (i < words.size()) {
    count = 0;
    while (words[i] == '6') {
      count++;
      i++;
    }
    result += (count > 9 ? "27" : (count > 3 ? "9" : string(count, '6')));
    result += words[i];
    i++;
  }
  cout << result << endl;
}

// Q4 不变初心数
int digitSum(int n) {
  int sum = 0;
  while (n) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
void Q4() {
  int l, n, hart = 0;
  cin >> l;
  int nums[l];
  for (int i = 0; i < l; i++) {
    cin >> nums[i];
  }
  cout << endl;
  for (int i = 0; i < l; i++) {
    n = nums[i];
    hart = digitSum(n);
    int j = 2;
    while (j <= 9) {
      if (digitSum(n * j) != hart)
        break;
      j++;
    }
    if (j > 9) {
      cout << hart << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

// Q5 答题卡
void Q5() {
  int n, m, x, y, len, pos;
  string input;
  cin >> n >> m;
  // 初始化空白二维码
  char qr[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      qr[i][j] = '.';
    }
  }
  // 填涂答题卡
  for (int i = 0; i < m; i++) {
    cin >> input;
    // 解析坐标
    len = input.size();
    if (input.find(";") != string::npos) {
      // 格式：答案1;答案2
      pos = input.find(";");
      x = stoi(input.substr(0, pos));
      y = stoi(input.substr(pos + 1));
    } else if (input.find("/") != string::npos) {
      // 格式：分子/分母
      pos = input.find("/");
      x = stoi(input.substr(0, pos));
      y = stoi(input.substr(pos + 1));
    } else {
      // 格式：4 位整数（不足补0）
      while (input.size() < 4) {
        input = "0" + input;
      }
      x = stoi(input.substr(0, 2));
      y = stoi(input.substr(2, 2));
    }
    // 将坐标位置涂黑
    qr[n - y][x - 1] = '#';
  }
  // 打印答题卡
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << qr[i][j];
    }
    cout << endl;
  }
}

#endif